package ${project.packageName}.${project.dataCenterType}.client;


import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 生成RowKey工具类
 *
 * @author caiqiang
 * @version 2016年8月4日
 * @see RowkeyUtil
 * @since
 */
public class RowkeyUtil {
    /**
     * 日志对象
     */
    private static final Logger LOG = LoggerFactory.getLogger(RowkeyUtil.class);

    /**
     * Description:创建rowkey
     * 
     * @param args
     * @return byte[]
     * @see
     */
    public static byte[] generateHashRowkey(String... args) {
        if (args == null || args.length == 0) {
            return null;
        }

        byte[] phoneByte = Bytes.toBytes(args[0]);
        byte[] rowKeyHash = Bytes.toBytes((short)(args[0].hashCode() & 0x7fff));
        byte[] rowkey = Bytes.add(rowKeyHash, phoneByte);
        for (int i = 0; i < args.length; i++ ) {
            if (i == 0) {
                continue;
            }
            rowkey = Bytes.add(rowkey, Bytes.toBytes(args[i]));
            LOG.info(args[i]);
        }

        return rowkey;
    }
}
